﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="原料入库单.aspx.cs" Inherits="syc.Store.原料入库单" %>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript" language="javascript" src="/common.js"></script>
    <script src="jquery.js" type="text/javascript"></script>
    
<script type="text/javascript">
        var mt = document.getElementById("mt"); //主表格
        var i;

        //读取TABLE的值，并计算出金额
        //
        //
        function calc() {
            var n, zl, zs;
            var zzl = 0;
            var zzs = 0;
            for (i = 1; i <= 4; i++) {

                zs = Number(document.getElementById("dd" + i + "1").innerHTML);
                zl = Number(document.getElementById("dd" + i + "2").innerHTML);
                if (zs != 0 && !isNaN(zs)) {
                    zzs += zs;
                }
                if (zl != 0 && !isNaN(zl)) {
                    zzl += zl;
                }
                if (document.getElementById("DanWei_0").checked) {
                    n = Number(document.getElementById("dd" + i + "2").innerHTML) * Number(document.getElementById("dd" + i + "3").innerHTML);
                }
                else {
                    n = Number(document.getElementById("dd" + i + "1").innerHTML) * Number(document.getElementById("dd" + i + "3").innerHTML);
                }
                if (n != 0 && !isNaN(n)) {
                    document.getElementById("dd" + i + "4").innerHTML = fixFloat(n, 2);
                }
            }
        }

        //Page_Load函数===============================================================================================================================
        function init() {
            //        document.getElementById("FenChang").onchange = function() {
            //            document.getElementById("box_FenChang").innerHTML = "生产单位：" + this.options[this.selectedIndex].text;
            //        };

            document.getElementById("GongHuo").onchange = function() {
                document.getElementById("Label_GongHuo").innerHTML = this.options[this.selectedIndex].text;
            };
            document.getElementById("GongHuo").onchange();
            document.getElementById("LeiBie").onchange = function() {
                document.getElementById("Label_LeiBie").innerHTML = this.options[this.selectedIndex].text;
            };
            document.getElementById("LeiBie").onchange();
            document.getElementById("Date1").onchange = function() {
                document.getElementById("Label_Date").innerHTML = this.value;
            };
            document.getElementById("Date1").onchange();

            document.getElementById("DanHao").onchange = function() {
                document.getElementById("Label_DanHao").innerHTML = "000000".substr(this.value.length) + this.value;
            };
            document.getElementById("DanHao").onchange();

            document.getElementById("DanWei_0").onclick = document.getElementById("DanWei_1").onclick = function() {
                document.getElementById("Label_DanWei").innerHTML = document.getElementById("DanWei_0").checked == true ? "吨" : "支";
                calc();
            };
            document.getElementById("DanWei_0").onclick();
            var spans = document.getElementsByTagName("span");
            if (readonly) {//只读处理
                for (i = 0; i < spans.length; i++) {
                    if (spans[i].className == "ed") {
                        spans[i].className = "";
                    }
                }
            }
            else {//使之可编辑
                for (i = 0; i < spans.length; i++) {
                    if (spans[i].className == "ed") {
                        spans[i].contentEditable = true;
                        //spans[i].tabIndex = 1;
                    }
                }
            }
            //建立三个列表，读入隐含位，并写入TABLE，初始化数字
            var zslist = document.getElementById("ZSList").value.split("|");
            var zllist = document.getElementById("ZLList").value.split("|");
            var djlist = document.getElementById("DJList").value.split("|");

            for (i = 1; i <= 4; i++) {
                if (zslist.length >= i) {
                    document.getElementById("dd" + i + "1").innerHTML = zslist[i - 1];
                }
                if (zllist.length >= i) {
                    document.getElementById("dd" + i + "2").innerHTML = zllist[i - 1];
                }
                if (djlist.length >= i) {
                    document.getElementById("dd" + i + "3").innerHTML = djlist[i - 1];
                }
            }
            document.getElementById("Label_BeiZhu").innerHTML = document.getElementById("BeiZhu").value;
            calc();
        }
        
        //按键处理===================================================================================================
        document.onkeydown = function(e) {
            var o;
            if (!e) e = window.event;
            var tag = e.srcElement;
            if (!tag) tag = e.target;
            if (tag.tagName == "INPUT" && tag.className == "textbox" || tag.tagName == "SELECT" || tag.tagName == "SPAN" || tag.tagName == "DIV") {
                if (e.keyCode == 13) {
                    if (tag.id == "Label_BeiZhu") {
                        return false;
                    }
                    else {
                        e.keyCode = 9; //跳到下一格
                    }
                }
            }
            else if (e.keyCode == 8) {
                return false;
            }
        }

        //编辑后检测======================================================================================================
        document.onfocusout = function(e) {
            if (!e) e = window.event;
            var tag = e.srcElement;
            if (!tag) tag = e.target;

            if (tag.tagName == "SPAN" && tag.parentNode.tagName == "TD") {
                if (tag.id.substr(0, 2) == "dd") {
                    calc();
                }

            }
        }

        //提交前检测====================================================================================
        //提交前，会将TABLE所有的值都读入数组，并JOIN成单一字符串，然后存入HIDDEN栏目
        function checkinput() {
            var o = document.getElementById("DanHao");
            if (o.value == "") {
                parent.showmsgbox("“单号”必须填写。");
                return false;
            }
            else if (o.value.match(/[^0-9]/)) {
                parent.showmsgbox("“单号”只能录入正数。");
                return false;
            }

            document.getElementById("BeiZhu").value = document.getElementById("Label_BeiZhu").innerText;

            var zslist = new Array();
            var zllist = new Array();
            var djlist = new Array();
            var k = 0;
            for (i = 1; i <= 4; i++) {
                if (document.getElementById("dd" + i + "4").innerText != "") {
                    zslist[k] = document.getElementById("dd" + i + "1").innerText;
                    zllist[k] = document.getElementById("dd" + i + "2").innerText;
                    djlist[k] = document.getElementById("dd" + i + "3").innerText;
                    k++;
                }
            }

            document.getElementById("ZSList").value = zslist.join("|");
            document.getElementById("ZLList").value = zllist.join("|");
            document.getElementById("DJList").value = djlist.join("|");

            return true;
        }


        //导出Excel==============================================================================
        function Export() {
            var code = document.getElementById("mt").outerHTML;
            form2.content.value =
"<html xmlns:o='urn:schemas-microsoft-com:office:office'\nxmlns:x='urn:schemas-microsoft-com:office:excel'\nxmlns='http://www.w3.org/TR/REC-html40'>\n<head>\n<meta http-equiv=Content-Type content='text/html; charset=utf-8'>\n<style>\n<!--table\n@page\n{mso-header-data:;\nmso-footer-data:;\nmargin:.79in .12in .59in .12in;\nmso-header-margin:.51in;\nmso-footer-margin:.51in;\nmso-horizontal-page-align:center;}\ntd{mso-number-format:'\@';}\ntd.ed,td.gh,td.bb{border:.5pt solid black;font-size:10pt;text-align:center;height:24px;padding:0px;}\ntd.zl{border:.5pt solid black;font-size:10pt;text-align:center;height:24px;padding:0px;mso-number-format:'0\.0_ '}\ntd.cd{border:.5pt solid black;font-size:10pt;text-align:center;height:24px;padding:0px;mso-number-format:'0\.00_ '}\ntd.zs{border:.5pt solid black;font-size:10pt;text-align:center;height:24px;padding:0px;mso-number-format:General}\n-->\n</style>\n<!--[if gte mso 9]><xml>\n<x:ExcelWorkbook>\n<x:ExcelWorksheets>\n<x:ExcelWorksheet>\n<x:Name>产品判定入库通知书</x:Name>\n<x:WorksheetOptions>\n<x:DefaultRowHeight>285</x:DefaultRowHeight>\n<x:Print>\n<x:ValidPrinterInfo/>\n<x:Scale>100</x:Scale>\n<x:PaperSizeIndex>9</x:PaperSizeIndex>\n<x:HorizontalResolution>200</x:HorizontalResolution>\n<x:VerticalResolution>200</x:VerticalResolution>\n</x:Print>\n<x:Selected/>\n<x:Panes>\n<x:Pane>\n<x:Number>3</x:Number>\n<x:ActiveRow>5</x:ActiveRow>\n<x:ActiveCol>0</x:ActiveCol>\n</x:Pane>\n</x:Panes>\n</x:WorksheetOptions>\n</x:ExcelWorksheet>\n</x:ExcelWorkbook>\n</xml><![endif]-->\n</head>\n<body>"
        + code + "</body></html>";
            form2.submit();
        }


        $(document).ready(function() {

        init();

            //处理选择质保书重量，还是榜重 ================================================================
            //只会改变TABLE里第一行的数值，因为这个涉及到人工拆分的问题
            //将Radio和TEXTBOX上的值相互绑定
            $("#Rd_bz").val($("#ZZL").val());
            $("#Rd_zb").val($("#ZBZ").val());
            //监听which_weight组变化事件
            //当which_weight组变化时，仅仅更新dd12
            $("input[name='which_weight'][type='radio']").click(function() {
                var item = $("input[name='which_weight'][type='radio']:checked").val();
               $("#dd12").html(item);
            });

            //当总支数变化时，联动表项变化 ================================================================
            //监听总支数TEXBOX变化事件,仅仅更新dd11
            $("#ZZS").change(function() {
                var item = $("#ZZS").val();
                //Just For Debug
                //alert(item);
                $("#dd11").html(item);
            });


            //处理成品骨子,给杨萍做的特异化的功能==========================================================            
            var checkBox = $("#LeiBie").val();
            var list = [5, 6, 105, 106];

            if (checkBox == 5 || checkBox == 6 || checkBox == 105 || checkBox == 106) {
                $('table').find('td').each(function(i) {//搜寻表格里的每一个区间
                    if (i % 8 == 3) { //‘8’代表表格总共有8列，如果区间编号被8整除，那么它就属于第一列
                        $(this).addClass('danwei').hide();
                    } //给区间加上特定样式
                });
                $("#Hshuliang").html("支 数");
            }

            $("#LeiBie").change(function() {
                var checkBox = $("#LeiBie").val();
                var list = [5, 6, 105, 106];

                if (checkBox == 5 || checkBox == 6 || checkBox == 105 || checkBox == 106) {
                    $('table').find('td').each(function(i) {//搜寻表格里的每一个区间
                        if (i % 8 == 3) { //‘8’代表表格总共有8列，如果区间编号被8整除，那么它就属于第一列
                            $(this).addClass('danwei').hide();
                        } //给区间加上特定样式
                    });
                    $("#Hshuliang").html("支 数");
                }

            });
            //====================================================================================================
        });
						
</script>
<form id="form1" runat="server" onsubmit="return checkinput();">

<asp:Label ID="IsReadonly" runat="server" Text="false" Visible="false"></asp:Label>
<asp:Label ID="LockSum" runat="server" Text="true" Visible="false"></asp:Label>

<asp:Label ID="Label_ID" runat="server" Text="0" Visible="false"></asp:Label>
<asp:Label ID="Label_List" runat="server" Text="" Visible="false"></asp:Label>
<asp:HiddenField ID="BeiZhu" runat="server" />

<asp:HiddenField ID="ZSList" runat="server" />
<asp:HiddenField ID="ZLList" runat="server" />
<asp:HiddenField ID="DJList" runat="server" />


<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
ConnectionString="<%$ ConnectionStrings:SCMConnectionString1 %>" 
SelectCommand="select ID, 名称 FROM 原料供货单位"></asp:SqlDataSource>


<div id="wintop" class="wintop">原料入库单</div>
<asp:Panel ID="Panel1" runat="server" CssClass="panel">
<!-- =================================================================================================== -->
<!-- ========                               原料类别列表                                     =========== -->
<!-- ========                                                                               =========== -->
<!-- =================================================================================================== -->
<asp:SqlDataSource ID="DS_LeiBie" runat="server" 
                   ConnectionString="<%$ ConnectionStrings:SCMConnectionString1 %>" 
                    SelectCommand="SELECT [ID],[品名]+' '+[钢级]+' '+[规格] AS 名称 FROM [原料]" >
</asp:SqlDataSource>
原料：
<asp:DropDownList ID="LeiBie" runat="server" Width="250px" Font-Size="12px" DataSourceID="DS_LeiBie" 
                               DataTextField="名称" DataValueField="ID">
</asp:DropDownList>
<!-- =================================================================================================== -->
<asp:RadioButtonList ID="DanWei" runat="server" RepeatDirection="Horizontal" 
        RepeatLayout="Flow">
        <asp:ListItem Selected="True">吨</asp:ListItem>
        <asp:ListItem>支</asp:ListItem>
    </asp:RadioButtonList>
    
<span style="margin-left:6px;"></span>供货：<asp:DropDownList 
    ID="GongHuo" runat="server" DataSourceID="SqlDataSource2"  Width="120px"
    DataTextField="名称" DataValueField="ID"></asp:DropDownList>
    <br>
  单号：<asp:TextBox ID="DanHao" runat="server" CssClass="textbox" Width="80"></asp:TextBox>
    
    <asp:Button ID="Button_Save" runat="server" Text="保 存" class="mbutton" 
        UseSubmitBehavior="false" onclick="Button_Save_Click"/>
    <input type="button" value="关 闭" class="mbutton" onclick="parent.swin2_close();" />
</asp:Panel>
<asp:Panel ID="Panel2" runat="server" CssClass="panel">
日期：<asp:TextBox ID="Date1" runat="server" CssClass="textbox" Width="100"></asp:TextBox>
<img alt="" src="/Icons/29.png" align="middle" onclick="makecalendar(document.getElementById('Date1').value, document.getElementById('Date1'));" />
<span style="margin-left:10px;"></span>
<!-- =================================================================================================== -->
<!-- ========                               选择最终保存为质保书还是总榜重                  =========== -->
<!-- ========                                                                               =========== -->
<!-- =================================================================================================== -->
<input id="Rd_bz" name="which_weight" type="radio" checked="checked" />
总磅重：<asp:TextBox ID="ZZL" runat="server" CssClass="textbox" Width="80" 
Enabled="false" Text="0" BackColor="#dddddd">
</asp:TextBox>吨

<span style="margin-left:10px;"></span>
<input id="Rd_zb" name="which_weight" type="radio" />
质保重量：<asp:TextBox ID="ZBZ" runat="server" CssClass="textbox" Width="80" 
Enabled="false" Text="0" BackColor="#dddddd">
</asp:TextBox>吨
<!-- =================================================================================================== -->


<span style="margin-left:10px;"></span>总支数：<asp:TextBox ID="ZZS" runat="server" CssClass="textbox" Width="60" Enabled="true" Text="0"></asp:TextBox>支
</asp:Panel>
<asp:Panel ID="Panel3" runat="server">
<script>putBillHead();</script>
<style>
td.bb,td.ed{border:.5pt solid black;}
td.ed{background-color:#d2e8ae;}
span.ed{display:inline-block;width:100%;height:100%;line-height:26px;overflow:hidden;background-color:#d2e8ae;}

</style>
<table id="mt" border="0" cellpadding="0" style="border-collapse: collapse;text-align:center;font-size:14px;">
	<tr height="30">
		<td colspan="8" style="font-size:20px;"><b>专用原（辅）料入库验收单</b></td>
	</tr>
	<tr height="20">
		<td colspan="8" align="left" style="padding-left:10px;">编码：SYC/ZJ-WL-12</td>
	</tr>
	<tr height="20">
		<td colspan="2" align="left" style="padding-left:10px;">供货单位：<span id=Label_GongHuo></span></td>
		<td colspan="3" id=Label_Date></td>
		<td colspan="3" align="right" style="color:red;padding-right:10px;">No.<span id=Label_DanHao></span></td>
	</tr>
	<tr>
		<td width="120" class=bb height="32">材料名称(钢级)</td>
		<td width="100" class=bb>规 格</td>
		<td width="80" class=bb>批次(编号)</td>
		<td width="50" class=bb>单 位</td>
		<td width="70" id="Hshuliang" class=bb>数 量</td>
		<td width="70" class=bb>重 量</td>
		<td width="90" class=bb>单 价</td>
		<td width="100" class=bb>金 额</td>
	</tr>
	<tr>
		<td class=bb height="26" id="Label_LeiBie"></td>
		<td class=bb></td>
		<td class=bb></td>
		<td class=bb id="Label_DanWei"></td>
		<td class=bb><span id=dd11 class=ed></span></td>
		<td class=bb><span id=dd12 class=ed></span></td>
		<td class=bb><span id=dd13 class=ed></span></td>
		<td class=bb id=dd14></td>
	</tr>
	<tr>
		<td class=bb height="26"></td>
		<td class=bb></td>
		<td class=bb></td>
		<td class=bb></td>
		<td class=bb><span id="dd21" class="ed"></span></td>
		<td class=bb><span id="dd22" class="ed"></span></td>
		<td class=bb><span id="dd23" class="ed"></span></td>
		<td class=bb id="dd24"></td>
	</tr>
	<tr>
		<td class=bb height="26"></td>
		<td class=bb></td>
		<td class=bb></td>
		<td class=bb></td>
		<td class=bb><span id=dd31 class=ed></span></td>
		<td class=bb><span id=dd32 class=ed></span></td>
		<td class=bb><span id=dd33 class=ed></span></td>
		<td class=bb id=dd34></td>
	</tr>
	<tr>
		<td class=bb height="26"></td>
		<td class=bb></td>
		<td class=bb></td>
		<td class=bb></td>
		<td class=bb><span id=dd41 class=ed></span></td>
		<td class=bb><span id=dd42 class=ed></span></td>
		<td class=bb><span id=dd43 class=ed></span></td>
		<td class=bb id=dd44></td>
	</tr>
	<tr>
		<td class=bb height="26">备注</td>
		<td class=bb colspan=7 style="text-align:left;"><span id=Label_BeiZhu class=ed></span></td>
	</tr>
	<tr height="26">
		<td colspan="8" align="left">
		<span style="display:inline-block;width:160px;margin-left:15px;">采购主管：</span>
		<span style="display:inline-block;width:150px;margin-left:5px;">采购员：</span>
		<span style="display:inline-block;width:160px;margin-left:5px;">仓储主管：</span>
		<span style="display:inline-block;width:150px;margin-left:5px;">库管员：</span>		
		</td>
	</tr>
</table>

<script type="text/javascript">putBillFoot();</script>

</asp:Panel>

</form>
<script type="text/javascript">
var notice = "<%=this.Notice %>";//提示信息
    var readonly = <%=this.IsReadonly.Text %>;
    var locksum = <%=this.LockSum.Text %>;
    if (notice != "") {
        parent.showmsgbox(notice);
    }
</script>
<script type="text/javascript">

</script>
</body>
</html>
